import AutoChart from '@/components/Echarts/AutoChart';
// @ts-ignore
import { medicinenewtransaction } from '@/services/api';
import { BorderBox1 } from '@jiaminghi/data-view-react';
import { useEffect } from 'react';
import { useImmer } from 'use-immer';
import './Chart4.less';

const Chart3: React.FC = () => {
  const [options, setOptions] = useImmer({
    legend: {
      data: ['成交额', '出口金额'],
      textStyle: {
        color: '#fff'
      } 
    },
    grid: {
      top: '12%',
      left: '7%',
      right: '7%',
      bottom: '8%',
      containLabel: true,
    },
    tooltip: {},
    xAxis: {
      data: [],
      splitLine: {
        show: false,
      },
    },
    yAxis: {},
    series: [
      {
        name: '成交额',
        type: 'line',
        data: [],
        emphasis: {
          focus: 'series',
        },
        animationDelay: function (idx) {
          return idx * 10;
        },
      },
      {
        name: '出口金额',
        type: 'line',
        data: [],
        emphasis: {
          focus: 'series',
        },
        animationDelay: function (idx) {
          return idx * 10 + 100;
        },
      },
    ],
    animationEasing: 'elasticOut',
    animationDelayUpdate: function (idx) {
      return idx * 5;
    },
  });

  useEffect(() => {
    medicinenewtransaction().then((res) => {
      setOptions((draft) => {
        draft.xAxis.data = res.data.map((i) => i.name);
        draft.series[0].data = res.data.map((i) => Number(i.value.split('-')[0]));
        draft.series[1].data = res.data.map((i) => Number(i.value.split('-')[1]));
      });
    });
  }, []);
  return (
    <>
      <div className="'marginb-10">
        <BorderBox1 color={['#396993', '#396993']}>
          <div className="echart_title">
            <div>中药成交额</div>
          </div>
          <div className="padding-5" style={{ height: 290 }}>
            <AutoChart option={options as any}></AutoChart>
          </div>
        </BorderBox1>
      </div>
    </>
  );
};
export default Chart3;
